package com.huawei.smartcity0102.util;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * @author ZengYunyi
 * @description:
 * @date :2022/1/2 14:03
 */
public class BannerAd extends BannerAdapter<Object, BannerAd.V> {
    public BannerAd(List<Object> datas) {
        super(datas);
    }

    @Override
    public V onCreateHolder(ViewGroup viewGroup, int i) {
        ImageView imageView=new ImageView(viewGroup.getContext());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return new V(imageView);
    }

    @Override
    public void onBindView(V v, Object o, int i, int i1) {
        if(o instanceof String){
            Glide.with(v.ig.getContext()).load(Http.base+o).into(v.ig);
        }else {
            Glide.with(v.ig.getContext()).load(o).into(v.ig);
        }
    }

    static class V extends RecyclerView.ViewHolder{
    ImageView   ig;
        public V(@NonNull ImageView itemView) {
            super(itemView);
            ig=itemView;
        }
    }
}
